<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap  PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="${selectSeg.table.pageNo}">

<#--基于主键进行的等值查询sql-->
<#if selectSeg.remark??>
    ${selectSeg.remark}
</#if>
    <${selectSeg.type?lower_case} id="${selectSeg.id}" parameterClass="${selectSeg.parameterClass}" resultClass="${selectSeg.resultClass}">
        SELECT
        <#list selectSeg.table.columns as column>
            ${column.column} AS ${column.fieldName} <#if column_has_next>,</#if>
        </#list>
        FROM ${selectSeg.table.schema}.${selectSeg.table.name}
        WHERE 1=1
    <#list  selectSeg.table.columns as column>
        <#--if判断时，布尔值是直接判断的，但是字段名称需要自己去掉前面的is-->
        <#if column.pk==true>
        AND ${column.column} = #${column.fieldName}#
            <#else>
        <isNotEmpty prepend="AND " property="${column.fieldName}">
            ${column.column} like '%$${column.fieldName}$%'
        </isNotEmpty>
        </#if>
    </#list>
    </${selectSeg.type?lower_case}>

<#--新增的SQL-->
<#if insertSeg.remark??>
    ${insertSeg.remark}
</#if>
    <${insertSeg.type?lower_case} id="${insertSeg.id}" parameterClass="${insertSeg.parameterClass}">
        INSERT INTO ${selectSeg.table.schema}.${selectSeg.table.name}(
        <#list insertSeg.table.columns as column>
            ${column.column} <#if column_has_next>,</#if>
        </#list>)VALUES(
        <#list insertSeg.table.columns as column>
            #${column.fieldName}# <#if column_has_next>,</#if>
        </#list>)
    </${insertSeg.type?lower_case}>

<#--删除的SQL-->
<#if deleteSeg.remark??>
    ${deleteSeg.remark}
</#if>
    <${deleteSeg.type?lower_case} id="${deleteSeg.id}" parameterClass="${deleteSeg.parameterClass}">
        DELETE FROM ${selectSeg.table.schema}.${selectSeg.table.name}
        WHERE 1=1
        <#list deleteSeg.table.columns as column>
        <#if column.pk==true>
        AND ${column.column} = #${column.fieldName}#
        </#if>
        </#list>
    </${deleteSeg.type?lower_case}>

<#--修改的SQL-->
<#if updateSeg.remark??>
    ${updateSeg.remark}
</#if>
    <${updateSeg.type?lower_case} id="${updateSeg.id}" parameterClass="${updateSeg.parameterClass}">
        UPDATE ${updateSeg.table.schema}.${updateSeg.table.name}
        SET
    <#list updateSeg.table.columns as column>
        <#if column.pk==false>
            ${column.column} = #${column.fieldName}#<#if column_has_next>,</#if>
        </#if>
    </#list>
        WHERE 1=1
        <#list updateSeg.table.columns as column>
        <#if column.pk==true>
        AND ${column.column} = #${column.fieldName}#
        </#if>
        </#list>
    </${updateSeg.type?lower_case}>

</sqlMap>